package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 */
@Component
@ControllerAdvice
public class NcExceptionHandler {




    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result ex(Exception ex){
        ex.printStackTrace();
        return Result.errorMessage(ResponseEnum.SERVER_ERROR.getMessage());
    }



    @ExceptionHandler(value = NcException.class)
    @ResponseBody
    public Result ex(NcException ex){
        ex.printStackTrace();
        return Result.errorMessage(ex.getMessage());
    }
}
